package com.ymatou.iapi.livequery.testcase;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livequery.service.GetActivityIdsBySellerIdsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.database.mongo.LiveBasicInfoWapper;
import com.ymttest.database.sqlwapper.YmtLiveWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

@TestSuite
public class Ts_GetActivityIdsBySellerIds{
	private static GetActivityIdsBySellerIdsCall getActivityIdsBySellerIdsCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据多个直播id获取直播列表");
	}

	@Before
	public void caseUp() {
		getActivityIdsBySellerIdsCall=new GetActivityIdsBySellerIdsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getActivityIdsBySellerIdsCall.getOpurl());
	}
	
	
	/**
	 * 报文断言
	 * @param dataStr
	 * @throws Exception
	 */
	public void getReturnCode(JSONObject result) throws Exception {
	    try {	    	
			//返回报文断言		
			String code =  result.getString("Code");
			Logger.verifyIsContains(200, code, "\"Code\":200");
			String bCode =  result.getString("BCode");
			Logger.verifyIsContains(0, bCode, "\"BCode\":200");
			String msg =  result.getString("Msg");
			Logger.verifyIsContains("操作成功", msg, "\"Msg\":操作成功");	
	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  
	}	
	
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetActivityIdsBySellerIds_001() {
		Logger.start(true,"根据多个直播id获取直播列表（未开始的直播无商品）");
		try {
			//TODO 补全case代码
			//新建一个未开始的直播
			Integer activityId = LiveCallService.createLiveBeginInFuture(sellerName,sellerId).getJSONObject("Data").getInt("ActivityId");
			
			List<Integer> sellerIdList=new ArrayList<>();
			sellerIdList.add(sellerId);
			
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("SellerIds", new JSONArray(sellerIdList));
			
			JSONObject result =  getActivityIdsBySellerIdsCall.callAndGetReturnData(updateMap);
			
			//报文断言
			getReturnCode(result);				
			
			int activityIdbyresult = result.getJSONObject("Data").getJSONArray("ActivityIds").getJSONObject(0).getInt("ActivityId");
			Logger.verifyEquals(activityId, activityIdbyresult, "直播id对比");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	

	
	
	
	
	
	
	
} 